<?php

namespace app\admin\controller\system;

use app\admin\service\system\GroupService;
use app\admin\service\system\MenuService;
use app\Request;
use app\BaseController;

class Group extends BaseController
{
    /**
     * 权限组
     * @author dgc<453342213@qq.com>
     */
    public function index()
    {
        try {
            $service = new GroupService();
            $res = $service->getList([]);
            returnDate($res);
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 获取权限树
     * @author dgc<453342213@qq.com>
     */
    public function getRule(){
        $service = new GroupService();
        $res = $service->getRule();
        returnDate($res);
    }

    /**
     * 操作
     * @param Request $request
     * @throws \Exception
     * @author dgc<453342213@qq.com>
     */
    public function saves(Request $request)
    {
        try {
            $param = $this->checkParam(['rules', 'status', 'title'], false);
            $res = (new GroupService())->saves($param, $request->param('id', 0));
            returnDate($res);
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }
}
